package com.briup.jz.web.controller;

import com.briup.jz.bean.Address;
import com.briup.jz.service.IAddressService;
import com.briup.jz.utils.Message;
import com.briup.jz.utils.MessageUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @ProjectName: jz
 * @Author: xjs
 * @Description: 地址接口
 * @Date: 2020/6/14 16:58
 */
@RestController
@RequestMapping("/address")
@Api(description = "地址管理接口")
public class AddressController {

    @Autowired
    private IAddressService iAddressService;

    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "唯一编号", required = true, paramType = "query")
    })
    @GetMapping("deleteById")
    public Message deleteById(Long id){
        iAddressService.deleteById(id);
        return MessageUtil.success("操作成功");
    }


    @GetMapping("saveOrUpdate")
    public Message saveOrUpdate(Address address){
        iAddressService.saveOrUpdate(address);
        return MessageUtil.success("操作成功");
    }

    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "唯一编号", required = true, paramType = "query")
    })
    @GetMapping("findAllByUserid")
    public Message findAllByUserid(Long id){
        return MessageUtil.success(iAddressService.findAllByUserid(id));
    }
}
